//package pub.developers.forum.infrastructure.audit;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Service;
//import pub.developers.forum.common.constant.Constant;
//import pub.developers.forum.common.enums.AuditStateEn;
//import pub.developers.forum.common.support.LogUtil;
//import pub.developers.forum.common.support.SafesUtil;
//import pub.developers.forum.infrastructure.dal.dao.PostsDAO;
//import pub.developers.forum.infrastructure.dal.dao.SensitiveWordsDAO;
//import pub.developers.forum.infrastructure.dal.dataobject.PostsDO;
//import pub.developers.forum.infrastructure.dal.dataobject.SensitiveWordsDO;
//
//import javax.annotation.Resource;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.stream.Collectors;
//
//@Slf4j
//@Service
//public class PostsAuditTask {
//
//    @Resource
//    private PostsDAO postsDAO;
//
//    @Resource
//    private SensitiveWordsDAO sensitiveWordsDAO;
//
//    @Scheduled(cron = "0/2 * * * * ? ")
//    public void task() {
//        List<PostsDO> postsDOS = postsDAO.query(PostsDO.builder()
//                .auditState(AuditStateEn.WAIT.getValue())
//                .isWordsFilter(Constant.IS_WORDS_FILTER_NO)
//                .build());
//        if (SensitiveFilterUtil.sensitiveWordMap == null){
//            initWordsTask();
//        }
//        SafesUtil.ofList(postsDOS).forEach(postsDO -> {
//            if (!SensitiveFilterUtil.contains(postsDO.getMarkdownContent())){
//                postsDO.setAuditState(AuditStateEn.PASS.getValue());
//            }
//            postsDO.setIsWordsFilter(Constant.IS_WORDS_FILTER_YES);
//            postsDAO.update(postsDO);
//        });
//    }
//
//
//
//    /**
//     * 初始化敏感词库,构建DFA算法模型
//     */
//    @Scheduled(cron = "0 0/10 * * * ? ")
//    public  void initWordsTask() {
//        try {
//            List<SensitiveWordsDO> list = sensitiveWordsDAO.queryAll();
//            List<String> wordsList = list.stream().map(SensitiveWordsDO::getWords).collect(Collectors.toList());
//            SensitiveFilterUtil.initSensitiveWordMap(wordsList);
//        } catch (Exception e) {
//            log.error( "初始化敏感词库任务报错！", e);
//        }
//    }
//
//}
